package cz.muni.fi.hauntedhouses.util;

import cz.muni.fi.hauntedhouses.entity.Human;
import cz.muni.fi.hauntedhouses.to.HumanTO;
import java.util.ArrayList;
import java.util.List;

public class HumanUtil {
    
    public static HumanTO entityToTO(Human human) {
        if (human == null) {
            return null;
        }
        
        HumanTO humanTo = new HumanTO();
        humanTo.setId(human.getId());
        humanTo.setName(human.getName());
        humanTo.setGender(human.getGender());
        humanTo.setWorstFear(human.getWorstFear());
        humanTo.setHouse(HouseUtil.toDTO(human.getHouse()));
        humanTo.setResistance(human.getResistance());
        humanTo.setScareMeter(human.getScareMeter());
        return humanTo;
    }
    
    public static Human TOToEntity(HumanTO humanTo) {
        if (humanTo == null) {
            return null;
        }
        
        Human human = new Human();
        human.setId(humanTo.getId());
        human.setName(humanTo.getName());
        human.setGender(humanTo.getGender());
        human.setWorstFear(humanTo.getWorstFear());
        human.setHouse(HouseUtil.toDAO(humanTo.getHouse()));
        human.setResistance(humanTo.getResistance());
        human.setScareMeter(humanTo.getScareMeter());
        return human;
    }
    
    public static List<HumanTO> listToDTO(List<Human> list) {
        List<HumanTO> humans = new ArrayList<HumanTO>();
        for (Human h : list) {
            humans.add(HumanUtil.entityToTO(h));
        }
        return humans;
    }
    
}
